package com.example.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.adapter.ViewpagerAdapter;
import com.example.fragment.LazyFragment;
import com.example.studyapplication.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: 葛浩杰
 * @Version: 1.0 2021/4/12
 */
public class ViewPagerFragmentActivity extends AppCompatActivity {

    private ViewPager2 mVp2;
    private List<Fragment> mFragmentList;

    public static void startActivity(Context context){
        context.startActivity(new Intent(context,ViewPagerFragmentActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_vp_fragment);

        initView();
    }

    private void initView() {
        mVp2 = findViewById(R.id.vp2);
        mFragmentList = new ArrayList<>();

        mFragmentList.add(LazyFragment.newInstance(0));
        mFragmentList.add(LazyFragment.newInstance(1));
        mFragmentList.add(LazyFragment.newInstance(2));
        mFragmentList.add(LazyFragment.newInstance(3));

        mVp2.setAdapter(new ViewpagerAdapter(getSupportFragmentManager(),this.getLifecycle(),mFragmentList));
    }
}
